import requests
from util.config import get_header,get_log
from bs4 import BeautifulSoup
from pprint import pprint
import json

BK = ['UILixModule','__pageContext__','helpCenterModule','googleAnalyticsModule','globalVariableModule','jserpBadgeCreateModule',]
AST = [
'decoratedJobPostingModule','topCardV2Module','companyDescriptionModule','jobDescriptionModule'
]
def test():
    # url = 'https://www.linkedin.com/jobs/view/358539683/'
    # # cookie = {'Cookie':'acw_tc=AQAAAABaaxPbfgIAkVEQcC6d2w3MCN9I; gr_user_id=b2f925ef-4994-4aee-bc7b-0a1395171968; _hp2_id.2147584538=%7B%22userId%22%3A%225837954218760983%22%2C%22pageviewId%22%3A%226402464240000847%22%2C%22sessionId%22%3A%225399898142871267%22%2C%22identity%22%3Anull%2C%22trackerVersion%22%3A%223.0%22%7D; acw_sc=595d91684bb40fb958bee4cc68da1d974e9921e1; identity=326737833%40qq.com; remember_code=1FQQAzGfLu; session=967213b1f06717d3b9ffc9db87c49f67b57c113e; _ga=GA1.2.1277010002.1490167436; _gid=GA1.2.689510366.1500605053; Hm_lvt_1c587ad486cdb6b962e94fc2002edf89=1498200405,1500027712,1500128389; Hm_lpvt_1c587ad486cdb6b962e94fc2002edf89=1500611307; gr_session_id_eee5a46c52000d401f969f4535bdaa78=c341a010-f85e-4a40-bfb9-8ea3cdcdbeb9'}
    # # req = requests.get(url,timeout=10,headers=get_header(),cookies=cookie)
    # req = requests.get(url,timeout=10,headers=get_header())
    # req.encoding = 'utf8'
    # with open('test/link_job_1.html','wb')as f:
    #     f.write(req.content)
    with open('test/link_job_1.html','rt')as f:
        html = f.read()

    soup = BeautifulSoup(html,'lxml')
    ret_dic = {}
    for sp in soup.find_all('code'):
        _id = sp.attrs['id']
        if _id in BK:
            continue
        jd  = json.loads(sp.string)
        ret_dic[_id] = jd

    # pprint(ret_dic)
    print(json.dumps(ret_dic))
        # break

    # print(sp)
    # person = Person(html)
    # ret = person.parse()
    # pprint(html)

if __name__ == '__main__':
    # main()
    # update()
    test()
